package com.tanhua.user.controller;

import com.tanhua.dubbo.server.pojo.UserFreeze;
import com.tanhua.user.service.UserService;
import com.tanhua.user.vo.PageResult;
import com.tanhua.user.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/users")
    public PageResult getUserData(@RequestParam(value = "pagesize",required = false,defaultValue = "20") Integer pagesize,
                                  @RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                                  @RequestParam(value = "id",required = false) Integer id,
                                  @RequestParam(value = "nickname",required = false) String nickname,
                                  @RequestParam(value = "city",required = false) String city
                                  ){

        return userService.getUserData(pagesize,page,id,nickname,city);
    }

    @GetMapping("/users/{userID}")
    public UserInfoVo getBaseUserData(@PathVariable("userID") String userID){
        UserInfoVo userInfoVo = userService.getUserInfoVo(userID);
        return userInfoVo;
    }

    @PostMapping("/users/freeze")
    public String freezeUser(@RequestBody UserFreeze userFreeze){
        return userService.freezeUser(userFreeze);
    }


    @PostMapping("/users/unfreeze")
    public String unfreezeUser(@RequestBody Map<String,Object> param){
        System.out.println(param);
        Integer userId = (Integer) param.get("userId");
        String reasonsForThawing = (String) param.get("frozenRemarks");
        return userService.unfreezeUser(userId, reasonsForThawing);
    }




}
